﻿namespace _18_日期和时间;

internal class Program
{
    private static void Main(string[] args)
    {
        #region 1_DateTime

        // DateTime值类型表示日期和时间

        #endregion

        #region 2_TimeSpan

        // TimeSpan值类型表示时间间隔

        #endregion

        #region 3_今天的日期

        // Console.WriteLine(DateTime.Now);

        #endregion

        #region 4_DateTime属性

        //string[] months = {"January", "February", "March", "April", "May",
        //        "June", "July", "September", "October", "November", "December"};

        //DateTime now = DateTime.Now;

        //Console.WriteLine("Today's date: {0}", now.Date); // 今天的日期
        //Console.WriteLine("Today is {0} day of {1}", now.Day, months[now.Month - 1]); // 这个月的第几天
        //Console.WriteLine("Today is {0} day of {1}", now.DayOfYear, now.Year); // 今年的第几天
        //Console.WriteLine("Today's time: {0}", now.TimeOfDay); // 当前时间
        //Console.WriteLine("Hour: {0}", now.Hour); // 小时
        //Console.WriteLine("Minute: {0}", now.Minute); // 分钟
        //Console.WriteLine("Second: {0}", now.Second); // 秒
        //Console.WriteLine("Millisecond: {0}", now.Millisecond); // 毫秒
        //Console.WriteLine("The day of week: {0}", now.DayOfWeek); // 星期几
        //Console.WriteLine("Kind: {0}", now.Kind); // DateTime.Kind枚举值

        #endregion

        #region 5_加减DateTime

        //DateTime dt = new DateTime(2019, 2, 22, 14, 0, 0);

        //DateTime dt1 = dt.AddSeconds(55);
        //DateTime dt2 = dt.AddMinutes(30);
        //DateTime dt3 = dt.AddHours(72);
        //DateTime dt4 = dt.AddDays(65);
        //DateTime dt5 = dt.AddDays(-65);
        //DateTime dt6 = dt.AddMonths(3);
        //DateTime dt7 = dt.AddYears(4);

        //Console.WriteLine(dt1.ToString("F"));
        //Console.WriteLine(dt2.ToString("F"));
        //Console.WriteLine(dt3.ToString("F"));
        //Console.WriteLine(dt4.ToString("F"));
        //Console.WriteLine(dt5.ToString("F"));
        //Console.WriteLine(dt6.ToString("F"));
        //Console.WriteLine(dt7.ToString("F"));

        #endregion

        #region 6_UTC时间

        //DateTime now = DateTime.Now;
        //DateTime utc = DateTime.UtcNow;

        //Console.WriteLine($"UTC time {utc:HH:mm:ss}");
        //Console.WriteLine($"Local time {now:HH:mm:ss}"); // 东八区

        #endregion

        #region 7_Unix时间

        // Console.WriteLine(DateTimeOffset.UtcNow.ToUnixTimeSeconds());

        #endregion

        #region 8_TimeSpan

        //string startTime = "7:00 AM";
        //string endTime = "8:30 PM";

        //// 计算时间间隔
        //TimeSpan elapsed = DateTime.Parse(endTime).Subtract(DateTime.Parse(startTime));

        //Console.WriteLine($"Time elapsed: {elapsed}");

        //DateTime now = DateTime.Today;
        //DateTime borodino_battle = new DateTime(0001, 1, 1);

        //TimeSpan diff = now - borodino_battle;

        //Console.WriteLine($"{diff.TotalDays} days have passed since the Battle of Borodino.");

        #endregion


        #region 9_格式化时间

        //DateTime now = DateTime.Now;

        //Console.WriteLine(now.ToString("d")); // 短日期格式
        //Console.WriteLine(now.ToString("D")); // 长日期格式
        //Console.WriteLine(now.ToString("F")); // 完整日期格式
        //Console.WriteLine(now.ToString("M")); // 月/日
        //Console.WriteLine(now.ToString("o")); // ISO 8601
        //Console.WriteLine(now.ToString("R")); // HTTP
        //Console.WriteLine(now.ToString("t")); // 短时间格式
        //Console.WriteLine(now.ToString("T")); // 长时间格式
        //Console.WriteLine(now.ToString("Y")); // 年/月

        #endregion

        #region 10_解析时间

        //string date_string = "11/5/2021";
        //DateTime dt = DateTime.Parse(date_string);
        //Console.WriteLine($"{dt:dddd MMMM, yyyy}");

        #endregion

        #region 11_时区

        //TimeZoneInfo localZone = TimeZoneInfo.Local;

        //Console.WriteLine("Current timezone: {0}", localZone.StandardName); // 本地时区
        //Console.WriteLine("Daylight name: {0}", localZone.DaylightName); // 夏令时

        //Console.WriteLine("Bias: {0}", localZone.BaseUtcOffset); // 时区偏移

        #endregion

        #region 12_判断闰年

        // Assume year >= 1582 in the Gregorian calendar.
        int[] years =
        {
            2000, 2002, 2004, 2008, 2012, 2016, 2020,
            1900, 1800, 1600
        };

        foreach (var year in years)
            if (DateTime.IsLeapYear(year))
                Console.WriteLine("{year} is a leap year");
            else
                Console.WriteLine("{year} is not a leap year");

        #endregion
    }
}